/*
 * @filename CustomApplicationRefreshedEventListener.java
 * @author barry
 * @version 0.0.1
 * @date 2020年4月24日
 */
package com.bnzj.cloud.config;

import com.bnzj.cloud.business.core.persistence.entity.SysUser;
import com.bnzj.cloud.business.core.service.SysUserService;
import com.bnzj.core.util.FbConstant;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * @author barry
 * @date 2020-04-24
 */
//@Component
public class CustomApplicationRefreshedEventListener implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        ApplicationContext applicationContext = event.getApplicationContext();
        if (applicationContext.getParent() != null && applicationContext instanceof ConfigurableApplicationContext) {
            SysUserService sysUserService = applicationContext.getBean(SysUserService.class);
            SysUser user = sysUserService.findByAccount(FbConstant.ADMIN);
            ((ConfigurableApplicationContext)applicationContext).getBeanFactory().registerSingleton(FbConstant.ADMIN, user);
        }
    }

}
